package com.ciccwm.auth.config;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Nacos配置.
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "nacos")
public class NacosConfig {
    private static final int DEFAULT_ACCESS_TOKEN_VALIDITY_SECONDS = 3600;
    private static final int DEFAULT_REFRESH_TOKEN_VALIDITY_SECONDS = 86400;
    private static final int DEFAULT_CONNECTION_TIMEOUT = 1000;
    private static final int DEFAULT_RETRY_TIME = 600;
    private static final int DEFAULT_MAX_RETRY = 32;

    private String serverAddr;
    private String namespace;
    private String group;
    private String username;
    private String password;

    @Bean
    public ConfigService configService() throws NacosException {
        return NacosFactory.createConfigService(serverAddr);
    }

    public int getAccessTokenValiditySeconds() {
        return DEFAULT_ACCESS_TOKEN_VALIDITY_SECONDS;
    }

    public int getRefreshTokenValiditySeconds() {
        return DEFAULT_REFRESH_TOKEN_VALIDITY_SECONDS;
    }

    public int getConnectionTimeout() {
        return DEFAULT_CONNECTION_TIMEOUT;
    }

    public int getRetryTime() {
        return DEFAULT_RETRY_TIME;
    }

    public int getMaxRetry() {
        return DEFAULT_MAX_RETRY;
    }
} 
